package com.heima.homework.day605_开班.Test2_获得条件班级;

import java.util.ArrayList;

public class ClassTest {

    public static void main(String[] args) {
        //创建2个ClassRoom对象并赋值，并且将ClassRoom对象添加到ArrayList<ClassRoom>集合中，调用getClassCount方法并接收，遍历返回的新集合输出新集合中所有元素信息
        ClassRoom cla = new ClassRoom("a", "J", 60);
        ClassRoom clb = new ClassRoom("b", "Java", 55);
        ClassRoom clc = new ClassRoom("c", "J", 50);
        ClassRoom cld = new ClassRoom("d", "Java", 45);
        ArrayList arrayList = new ArrayList();
        arrayList.add(cla);
        arrayList.add(clb);
        arrayList.add(clc);
        arrayList.add(cld);
        //定义一个ClassRoom类的集合变量接收返回的新集合
        ArrayList<ClassRoom> tjAli = getClassCount(arrayList);
        //遍历已经获取条件的集合
        for (int i = 0; i < tjAli.size(); i++) {
            //定义ClassRoom的班级变量接收这个符合条件的集合
            ClassRoom zgbj = tjAli.get(i);
            //打印出这个符合条件班级的所有信息
            System.out.println(zgbj.getClassName() + "  " + zgbj.getClassCount() + "  " + zgbj.getClassType());
        }
    }


    public static ArrayList<ClassRoom> getClassCount(ArrayList<ClassRoom> classRoom) {
        //获得班级人数大于50人，并且班级类型是Java的，添加到新的集合中返回
        ArrayList<ClassRoom> newAli = new ArrayList<>();

        for (int i = 0; i < classRoom.size(); i++) {
            ClassRoom tjbj = classRoom.get(i);

            if (tjbj.getClassCount() > 50 && tjbj.getClassType() == "Java") {
                // if (classRoom1.getClassCount() > 50 && "Java".equals(classRoom1.getType())) {
                newAli.add(tjbj);
            }
        }
        return newAli;

    }
}
